package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.publish.SearchPublishBo;
import com.zhuss.bean.vo.team.publish.ListPublishVo;
import com.zhuss.common.PageVo;
import com.zhuss.exception.WpsException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.team.db.dao.ext.InvestPublishDao;
import com.zhuss.team.db.dao.ext.QuestionDao;
import com.zhuss.team.db.entity.Invest;
import com.zhuss.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/26 13:25
 */
@Component("publishRead")
public class PublishRead {

    @Autowired
    private InvestPublishDao publishDao;

    /**
     * 用户列表
     * @param bo
     */
    public Object list(SearchPublishBo bo) {
        PageVo<ListPublishVo> result = new PageVo<ListPublishVo>();
        if (bo.getStartTime() != null){
            bo.setStartTime(DateUtil.toDateOnly(bo.getStartTime()));
        }
        if (bo.getEndTime() != null){
            bo.setEndTime(DateUtil.toDateOnlyEnd(bo.getEndTime()));
        }
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(publishDao.list(bo));
        result.setTotal(publishDao.countList(bo));
        return result;
    }

    /**
     * 详情
     * @param publishId
     * @throws WpsException
     */
    public Object detail(Long publishId) throws WpsException {
        Object result = publishDao.detail(publishId);

        if (result == null) {
            throw new WpsException(ExceptionCode.数据不存在);
        }
        return result;
    }

}
